package com.adrian.misc.fractal.color;

import java.awt.Color;

public class TestColorMap extends ColorMap {
	Color[] colTable;
	double offset=0.0;
	double multiplier=1.0;
	boolean reverse = false;
	public TestColorMap (String name, Color baseCol, Color startCol, Color endCol, int res) {
		this(name, baseCol, startCol, endCol, 0.0,1.0, false, res);
	}
	public TestColorMap (String name, Color baseCol, Color startCol, Color endCol, double off, double mult, boolean rev, int res) {
		super(name);
		this.baseCol = baseCol;
		resolution = res;
		colTable = new Color[res];
		offset = off;
		multiplier = mult;
		reverse = rev;
		double rInc = ((double)(endCol.getRed() - startCol.getRed()))/(double)res;
		double gInc = ((double)(endCol.getGreen() - startCol.getGreen()))/(double)res;
		double bInc = ((double)(endCol.getBlue() - startCol.getBlue()))/(double)res;
		System.out.println("StartCol:" + startCol + "," + endCol);
		System.out.println("Building color table: "+ res+"," + rInc + "," +gInc +"," + bInc);
		for (int i= 0; i < res; i++) {
			//System.out.println("Color:" +i);
			colTable[i] = new Color((int)(startCol.getRed() +i * rInc),
									(int)(startCol.getGreen() + i * gInc),
									(int)(startCol.getBlue() + i * bInc) );
		}
	}
/*	private double func(double normVal) {
		return Math.sin(2*Math.pow(normVal-1.05,6));
	} */
	private double func(double normVal) {
		
		double val= -1*Math.sin(Math.log( (reverse?(1-(normVal+offset)):(normVal+offset))*multiplier));
		return val<=0?0:val;
	}
	



	public Color getColor(double val) {
		double normVal = func(val);
		int num =  (int)( normVal * resolution);
		if ( num >= resolution) {
			return baseCol;
		}
		return colTable[num];
	}



}
